/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package index.nested;

import index.Reader;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 *
 * @author Danang
 */
public class NestedIndexReader extends Reader{
    
    public NestedIndexReader(String path) throws FileNotFoundException {
        super(path);
    }    
    
    protected int compareToken=-1;
    protected String[] strRead;
    private String nameFile;
    
    public String getToken() {
        if (strRead==null) {
            return null;
        }
        return strRead[0];
    }
    
    public Long getPositionRead() {
        if (strRead==null) {
            return null;
        }
        return Long.parseLong(strRead[1]);
    }
    
    public int getCompareToken() {
        return this.compareToken;
    }
    
    public void searchToken(String searchToken, long pos) throws IOException {
        String str;
        fileReader.seek(pos);
        while ((str=fileReader.readLine())!=null) {
            String[] tmp = str.split(" ");
            compareToken = searchToken.compareTo(tmp[0]);
            if (compareToken<=0) {
                if (compareToken==0) {
                    strRead = tmp;
                }
                break;
            }
            strRead = tmp;
        }
    }

    /**
     * @return the nameFile
     */
    public String getNameFile() {
        return nameFile;
    }

    /**
     * @param nameFile the nameFile to set
     */
    public void setNameFile(String nameFile) {
        this.nameFile = nameFile;
    }
    
    
}
